<template>
  <div class="comingSoon-wrap">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in list" :key="item.filmId" center>
        <div class="comingSoonFilm-item">
          <div class="comingSoonFilm-img">
            <img :src="item.poster" alt="海报">
          </div>
          <div class="comingSoonFilm-info">
            <div class="info-col">
              <span class="name">{{ item.name }}</span>
              <span class="filmType">{{ item.filmType.name }}</span>
            </div>
            <div class="label info-col">主演：{{ item.actors | actorsFilter }}</div>
            <div class="label premiereAt">上映日期：{{ item.premiereAt | dateFilter2 }}</div>
          </div>
          <div class="comingSoonFilm-buy">预购</div>
        </div>
      </van-cell>
    </van-list>
  </div>
</template>

<script>
import Vue from 'vue'
import { Cell, List } from 'vant'
import http from '../../util/http'

Vue.use(List).use(Cell) // 全局注册
export default {
  name: 'ComingSoon',
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      total: 0,
      currentPage: 0
    }
  },
  mounted () {
    http({
      url: `gateway?cityId=${this.$store.state.cityId}&pageNum=${this.currentPage}&pageSize=10&type=2&k=2558806`,
      headers: {
        'X-Host': 'mall.film-ticket.film.list'
      }
    }).then((res) => {
      this.list = res.data.data.films
      this.total = res.data.data.total
    })
  },
  methods: {
    onLoad () {
      // 组件被销毁后，浏览器会记录滚动条的位置。当切回该组件时，可能会触发@load事件，而此时this.total也等于0，所以可能还没滚动懒加载就结束了
      if (this.list.length === this.total && this.list.length !== 0) {
        this.finished = true
        return
      }
      this.currentPage++
      http({
        url: `/gateway?cityId=${this.$store.state.cityId}&pageNum=${this.currentPage}&pageSize=10&type=1&k=7899293`,
        headers: {
          'X-Host': 'mall.film-ticket.film.list'
        }
      }).then(res => {
        this.list = [...this.list, ...res.data.data.films]
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.comingSoonFilm-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.comingSoonFilm-info {
  padding: 0 10px;
  width: 60%;

  .label {
    color: #797d82;
    font-size: 13px;
    width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
  }

  .name {
    margin-right: 5px;
    font-size: 16px;
  }
}

.comingSoonFilm-buy {
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid #ffb232;
  width: 50px;
  height: 25px;
  color: #ffb232;
  font-size: 13px;
  border-radius: 2px;
}

.comingSoonFilm-img {
  background: rgb(249, 249, 249);

  img {
    width: 17.6vw;
    height: 25.07vw;
  }
}

.filmType {
  background-color: #d2d6dc;
  border-radius: 2px;
  font-size: 9px;
  color: #ffffff;
  height: 14px;
  line-height: 14px;
  padding: 0 2px;
  font-family: system-ui, serif;
}
</style>
